import math
import pyglet.gl
import pyglet.graphics

def draw_line_loop(points, color = None):
    """
    helper function to draw a specific line loop, specified by a list 
    of points (iterable of Vec2ds) in a specified color (not implemented).
    """
    if color is not None:
        if len(color) == 3: pyglet.gl.glColor3f(*color)
        if len(color) == 4: pyglet.gl.glColor4f(*color)
    
    verts = []
    for point in points:
        verts.extend(point)
    
    pyglet.graphics.draw(len(verts)/2, pyglet.gl.GL_LINE_LOOP,
        ('v2f', verts)
    )

_points = []
for i in range(100):
    angle = i * 2 * math.pi / 100
    _points.append(math.cos(angle))
    _points.append(math.sin(angle))
circle_list = pyglet.graphics.vertex_list(len(_points)/2,
                                          ('v2f', _points))

def draw_circle(position, radius, color = None):
    """
    helper function to draw a circle at a given position (Vec2d) with a 
    given radius in a specified color.
    """
    if color is not None:
        if len(color) == 3: pyglet.gl.glColor3f(*color)
        if len(color) == 4: pyglet.gl.glColor4f(*color)
    
    pyglet.gl.glPushMatrix()
    pyglet.gl.glTranslatef(position[0], position[1], 0.)
    pyglet.gl.glScalef(radius, radius, 0)
    circle_list.draw(pyglet.gl.GL_LINE_LOOP)
    pyglet.gl.glPopMatrix()